package src.client;

import java.util.*;

public class FromQuery {
	private final String fromQuery;
	public FromQuery(String fromQuery) {
		this.fromQuery = fromQuery.toLowerCase();
	}
	public List<PairValue> queryParse(){
		try{
			List<PairValue> returnedList=new ArrayList<PairValue>();
			List<String> items=Utilities.SplitByRegex(fromQuery,"from ");
			if(items.size()==1){
				items=Utilities.SplitByRegex(items.get(0),"(,)");
				for(String item:items){
					List<String> tempItem=Utilities.SplitByRegex(item,"( )"); 
					if(tempItem.size()==2){
						returnedList.add(new PairValue(tempItem.get(0),tempItem.get(1),true));
	                }else if(tempItem.size()==1){
	                	returnedList.add(new PairValue(tempItem.get(0),"",false));
	                }else{
	                    return null;
	                }
				}
			}else{
				return null;
			}
			return returnedList;
		}catch(Exception ex){
			return null;
		}
	}
}
